package cz.possoft.client.four.gui.components;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import cz.possoft.client.four.gui.panel.FourPanel;
import cz.possoft.client.utils.PanelHolderUtils;
import cz.possoft.serializable.generic.Location;

/**
  * Listener nastava pri oddelani mysi z sachovnice hry ctyri-v-rade
  * nebo pri stisku tlacitka nad touto sachovnici
  *
  * @author mara  
  */
public class FourMouseListener extends MouseAdapter {
	
	// nastava pokud mysi vyjedu z prostoru sachovnice	   
    public void mouseExited(MouseEvent me) {
    	if (!(PanelHolderUtils.getCurrentGamePanel() instanceof FourPanel)) {
    		return;
    	}    	
        if ((PanelHolderUtils.getCurrentGamePanel().getGame().isActive()) && (PanelHolderUtils.getCurrentGamePanel().getGame().jsemNaTahu())) {
            Location location = new Location(-1, -1);
            ((FourPanel)PanelHolderUtils.getCurrentGamePanel()).updateForPlaceWhereIsMouse(location);	            
        }          	
    }

    
    public void mousePressed(MouseEvent me) {
       	if (!(PanelHolderUtils.getCurrentGamePanel() instanceof FourPanel)) {
    		return;
    	}        	
        if ((PanelHolderUtils.getCurrentGamePanel().getGame().isActive()) && (PanelHolderUtils.getCurrentGamePanel().getGame().jsemNaTahu())
        		&& (!((FourPane)(PanelHolderUtils.getCurrentGamePanel().getGamePane())).getRingFigurkaLocation().isNull())) {
                    Location location = FourMouseMotionListener.getMouseLocation(me);
                    ((FourPanel)PanelHolderUtils.getCurrentGamePanel()).play(location);	            
        }   
    }	

}
